﻿using System;
using System.ComponentModel;

namespace ExFlash.Records
{
    [TypeConverter(typeof(CXFormRecordConverter))]
    public class CXFormRecord : ISwfSerializable
    {
        public Boolean HasAddTerms
        {
            get;
            protected set;
        }

        public Boolean HasMultTerms
        {
            get;
            protected set;
        }

        [Browsable(false)]
        public Byte Nbits
        {
            get;
            protected set;
        }

        public Int16 RedMultTerm
        {
            get;
            protected set;
        }

        public Int16 GreenMultTerm
        {
            get;
            protected set;
        }

        public Int16 BlueMultTerm
        {
            get;
            protected set;
        }

        public Int16 RedAddTerm
        {
            get;
            protected set;
        }

        public Int16 GreenAddTerm
        {
            get;
            protected set;
        }

        public Int16 BlueAddTerm
        {
            get;
            protected set;
        }

        #region ISwfSerializable Members

        public virtual void SwfDeserialize(BinaryBitReader reader)
        {
            HasAddTerms = reader.ReadBoolean();

            HasMultTerms = reader.ReadBoolean();

            Nbits = (Byte)reader.ReadInt32(4);

            if (HasMultTerms)
            {
                RedMultTerm = (Int16)reader.ReadInt32(Nbits);
                GreenMultTerm = (Int16)reader.ReadInt32(Nbits);
                BlueMultTerm = (Int16)reader.ReadInt32(Nbits);
            }

            if (HasAddTerms)
            {
                RedAddTerm = (Int16)reader.ReadInt32(Nbits);
                GreenAddTerm = (Int16)reader.ReadInt32(Nbits);
                BlueAddTerm = (Int16)reader.ReadInt32(Nbits);
            }

            reader.AlignBits();
        }

        public virtual void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class CXFormRecordConverter : ExpandableObjectConverter
    {

    }
}
